package com.example.figurehecheng.controller.merchant;

import com.example.figurehecheng.common.properties.JwtProperties;
import com.example.figurehecheng.common.result.Result;
import com.example.figurehecheng.domain.dto.MerchantLoginDTO;
import com.example.figurehecheng.service.IMerchantService;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.CrossOrigin;

import java.util.Map;

/**
 * <p>
 * 商家管理接口
 * </p>
 */

@RestController("adminMerchantController")
@RequestMapping("/merchant")
@Api(tags = "商家管理接口")
@RequiredArgsConstructor
@CrossOrigin
public class MerchantController {

    private final IMerchantService merchantService;
    private final JwtProperties jwtProperties;

    @PostMapping("/login")
    @ApiOperation(value = "商家登录", notes = "商家通过账号密码登录系统")
    @ApiResponses({
        @ApiResponse(code = 200, message = "登录成功"),
        @ApiResponse(code = 400, message = "请求参数错误"),
        @ApiResponse(code = 401, message = "账号或密码错误"),
        @ApiResponse(code = 403, message = "账号被禁用"),
        @ApiResponse(code = 500, message = "系统内部错误")
    })
    public Result<Map<String, Object>> login(
            @ApiParam(value = "商家登录信息", required = true)
            @RequestBody MerchantLoginDTO merchantLoginDTO) {
        Map<String, Object> result = merchantService.login(merchantLoginDTO);
        return Result.success(result);
    }
}
